package com.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.model.auto.Contacts;
import com.service.IContactsService;
import com.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author astupidcoder
 * @since 2022-09-14
 */
@RestController
@RequestMapping("/contacts")
public class ContactsController{
    @Autowired
    private IContactsService contactsService;

    @GetMapping("/getContacts")
    public R getContacts(String stuId) {
        List<Contacts> list = contactsService.list(new LambdaQueryWrapper<Contacts>()
                .eq(Contacts::getStuId, stuId));
        return R.ok(list);
    }

    @PostMapping("SaveOrUpdateContacts")
    public R SaveOrUpdateContacts(@RequestBody List<Contacts> contacts) {
        boolean result = contactsService.saveOrUpdateBatch(contacts);
        if (!result) {
            return R.error();
        }
        return R.ok();
    }
}
